/*
 * @Author: heyang
 * @Date: 2025-01-13 19:39:59
 * @LastEditors: heyang
 * @LastEditTime: 2025-02-10 18:54:12
 * @FilePath: \eng-proc-app\src\store\user.ts
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
 */
/*
 * @Author: heyang
 * @Date: 2025-01-13 19:39:59
 * @LastEditors: heyang
 * @LastEditTime: 2025-02-10 18:13:29
 * @FilePath: \eng-proc-app\src\store\user.ts
 * @Description:
 *
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved.
 */
import { defineStore } from 'pinia'
import { ref } from 'vue'

const initState = {
  nickname: '',
  avatar: '',
  token:
    '',
}

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref<IUserInfo>({ ...initState })

    const setUserInfo = (val: IUserInfo) => {
      userInfo.value = val
    }

    const clearUserInfo = () => {
      userInfo.value = { ...initState }
    }
    // 一般没有reset需求，不需要的可以删除
    const reset = () => {
      userInfo.value = { ...initState }
    }
    const isLogined = computed(() => !!userInfo.value.token)

    return {
      userInfo,
      setUserInfo,
      clearUserInfo,
      isLogined,
      reset,
    }
  },
  {
    persist: true,
  },
)
